package pub.tbc.toolkit;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pub.tbc.toolkit.function.Consumer;

import java.util.*;

/**
 * 对象工厂：封装一些工具的快捷创建及初始化操作
 *
 * @author tbc
 * @version 1.0 {2016年7月5日 上午10:43:14}
 */
public final class Factory {
    private Logger log = LoggerFactory.getLogger(Factory.class);

    private Factory() {
        throw new AssertionError("No " + getClass() + " instances for you!");
    }

    public static <T> ThreadLocal<T> newThreadLocal(final T t) {
        return new ThreadLocal<T>() {
            protected T initialValue() {
                return t;
            }
        };
    }

    public static <T> ThreadLocal<T> newThreadLocal() {
        return new ThreadLocal<T>();
    }

    @SafeVarargs
    public static <T> List<T> asArrayList(T... ts) {
        List<T> list = new ArrayList<>();
        Collections.addAll(list, ts);
        return list;
    }

    @SafeVarargs
    public static <T> LinkedList<T> asLinkedList(T... ts) {
        LinkedList<T> list = new LinkedList<>();
        Collections.addAll(list, ts);
        return list;
    }

    public static <K, V> Map<K, V> newHashMap() {
        return new HashMap<K, V>();
    }

    public static <K, V> Map<K, V> asHashMap(K key, V value) {
        Map<K, V> map = newHashMap();
        map.put(key, value);
        return map;
    }

    public static <K, V> Map<K, V> asHashMap(K k1, V v1, K k2, V v2) {
        Map<K, V> map = asHashMap(k1, v1);
        map.put(k2, v2);
        return map;
    }

    public static <K, V> Map<K, V> asHashMap(K k1, V v1, K k2, V v2, K k3, V v3) {
        Map<K, V> map = asHashMap(k1, v1, k2, v2);
        map.put(k3, v3);
        return map;
    }

    public static <K, V> Map<K, V> asHashMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
        Map<K, V> map = asHashMap(k1, v1, k2, v2, k3, v3);
        map.put(k4, v4);
        return map;
    }

    public static <K, V> Map<K, V> asHashMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
        Map<K, V> map = asHashMap(k1, v1, k2, v2, k3, v3, k4, v4);
        map.put(k5, v5);
        return map;
    }

    public static void main(String[] args) {

    }
}
